<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.prime.com.tr/ui">

<ui:composition template="/template/template-padrao.xhtml">

	<ui:define name="titulo">Manter modelos</ui:define>

	<ui:define name="baseCorpo">

		<h:form id="cadastroModeloForm">
		
			<script type="text/javascript">
				jQuery(function(){
					jQuery('input[id*=modelo]').focus();
				});
			</script>

			<h1 class="titulo-tela">Manter modelos</h1>

			<p:panel id="panelCadastrarModelo">

				<h1 class="ui-panel-titlebar ui-widget-header ui-corner-all">Dados cadastrais</h1>

				<h:panelGrid columns="1" cellspacing="10">
					<h:column>
						<h:outputLabel for="modelo" value="* Modelo:" />
						<br />
						<p:inputText id="modelo" 
							value="#{manterModelosBean.modelo.nmModelo}"
							label="Modelo" />

					</h:column>
					
					<h:column>
						<h:outputLabel for="fabricante" value="* Fabricante:" />
						<br />
						<h:selectOneMenu id="fabricante" label="Fabricante" style="width:160px;"
							styleClass="ui-inputfield ui-widget ui-state-default ui-corner-all"
							value="#{manterModelosBean.modelo.fabricante.id}" >
						    <f:selectItems value="#{manterModelosBean.todosFabricantes}" var="fab"
						    	itemValue="#{fab.value}" itemLabel="#{fab.label}"/>
					    	
						</h:selectOneMenu>
					</h:column>
					
				</h:panelGrid>
				<br />

			</p:panel>

			<br />
			<div align="right"><p:commandButton id="btn" value="Salvar"
				update="msgSistema, cadastroModeloForm, listaModelo"
				actionListener="#{manterModelosBean.salvarModelo}"
				style="margin-left:5px;" /> <p:commandButton id="botaoLimpar"
				value="Limpar" update="msgSistema, cadastroModeloForm, listaModelo"
				actionListener="#{manterModelosBean.limparCampos}"
				style="margin-left:5px;" /> </div>

		</h:form>

		<h:form id="listaModelo">

			<br />
			<br />
			<p:accordionPanel autoHeight="false" collapsible="true" style="padding:0;">
			<p:tab title="Modelos">
			
				<p:dataTable id="listaCadastroModelo" var="modelo"
					paginator="true" rows="10" paginatorPosition="bottom"
					value="#{manterModelosBean.todosModelo}"
					emptyMessage="Nenhum cadastro de Modelo encontrado">
	
					<p:column  filterBy="#{modelo.nmModelo}"
						headerText="Modelo" filterMatchMode="contains">
						<h:outputText value="#{modelo.nmModelo}" />
					</p:column>
					
					<p:column  filterBy="#{modelo.fabricante.nmFabricante}"
						headerText="Fabricante" filterMatchMode="contains">
						<h:outputText value="#{modelo.fabricante.nmFabricante}" />
					</p:column>
	
					<p:column style="width:100px;" headerText="Ações">
						<p:commandButton update="cadastroModeloForm"
							image="ui-icon ui-icon-pencil" immediate="true">
							<f:setPropertyActionListener value="#{modelo}"
								target="#{manterModelosBean.modelo}" />
							
						</p:commandButton>
						<p:commandButton oncomplete="confirmation.show()"
							image="ui-icon ui-icon-trash" immediate="true">
							<f:setPropertyActionListener value="#{modelo}"
								target="#{manterModelosBean.modeloAux}" />
						</p:commandButton>
					</p:column>
	
				</p:dataTable>
			
			</p:tab>
			</p:accordionPanel>

		</h:form>

		<h:form>
			<p:confirmDialog message="Deseja excluir o registro?"
				header="Confirmação" severity="alert" widgetVar="confirmation">

				<p:commandButton value="Sim"
					update="cadastroModeloForm, msgSistema, listaModelo"
					oncomplete="confirmation.hide()" immediate="true"
					actionListener="#{manterModelosBean.excluirModelo}" />
				<p:commandButton value="Não" onclick="confirmation.hide()"
					type="button" immediate="true" />

			</p:confirmDialog>
		</h:form>

	</ui:define>

</ui:composition>
</html>